package com.agu.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * 日期处理
 * 
 */
public class MyDateUtils {
	/** 时间格式(yyyy-MM-dd) */
	public final static String DATE_PATTERN = "yyyy-MM-dd";
	/** 时间格式yyyyMMddHHmmss) */
	public final static String DATE_PATTERN_S = "yyyyMMddHHmmss";
	/** 时间格式(yyyy-MM-dd HH:mm:ss) */
	public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";

	/**
	 * yyyy-MM-dd HH:mm:ss格式字符串返回时间戳
	 * @param dateStr
	 * @param n 
	 * @return
	 */
	public static long getStrDateTime(String dateStr,int n){
		try{
	        SimpleDateFormat format = new SimpleDateFormat(DATE_TIME_PATTERN); 
	        Date date = format.parse(dateStr); 			
			return date.getTime()/n;
		}catch(Exception e){
			return 0;
		}
	}
	/**
	 * yyyy-MM-dd HH:mm:ss格式字符串返回时间戳
	 * @param dateStr
	 * @return
	 */
	public static long getStrDateTime(String dateStr){
		return getStrDateTime(dateStr,1000);
	}
	
	
	public static String format(Date date) {
		return format(date, DATE_PATTERN);
	}

	public static String format(Date date, String pattern) {
		if (date != null) {
			SimpleDateFormat df = new SimpleDateFormat(pattern);
			return df.format(date);
		}
		return null;
	}

	public static String getTheDay(String Date, int n) {
		try {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			Date d = df.parse(Date);
			return df.format(new Date(d.getTime() + n * 24 * 60 * 60 * 1000l));

		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "";
		}

	}
	
	public static int getDaySpace(String beginDay, String endDay) {
		try {

			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");

			return Integer.parseInt(String
					.valueOf((df.parse(beginDay).getTime() - df.parse(endDay).getTime()) / (1000 * 24 * 60 * 60)));

		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0;
		}

	}
}
